﻿namespace Utility1
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;

    public class SiteNavigation
    {
       

        /* 2013*/

        public const string contronl_Chitiethoahong = "~/Page/chitiethoahong.ascx";
        public const string link_Chitiethoahong = "~/Canhan.aspx?page=Doanh-so-ban-the";

        public const string contronl_Sodocay = "~/Page/sodo.ascx";
        public const string link_Sodocay = "~/Canhan.aspx?page=So-do-he-thong";

       

        public const string contronl_hhTuvan_tructiep = "~/Page/hhTuvan.ascx";
        public const string link_hhTuvan_tructiep = "~/Canhan.aspx?page=Thong-ke-hoa-hong";

        public const string contronl_changeMK = "~/Page/matkhau.ascx";
        public const string link_changeMK = "~/Canhan.aspx?page=Thay-mat-khau";

        public const string contronl_Doanhsonhom = "~/Page/hhDoanhsonhom.ascx";
        public const string link_Doanhsonhom = "~/Canhan.aspx?page=Doanh-so-nhom";

        public const string contronl_IntroduceMysef = "~/Page/Introduced_myself.ascx";
        public const string link_IntroduceMysef = "~/Canhan.aspx?page=Ho-so-ca-nhan";

        public const string contronl_sodo = "~/Page/sodo.ascx";
        public const string link_sodo = "~/Canhan.aspx?page=so-do";

        public const string contronl_doanhso_banhang = "~/Page/doanhso_banhang.ascx";
        public const string link_doanhso_banhang = "~/Canhan.aspx?page=Hoa-hong-ban-le";

      

        public const string contronl_home = "~/Page/home.ascx";
        public const string link_home = "~/index.aspx?page=home";

        public const string contronl_detail = "~/Page/detail.ascx";
        public const string link_detail = "~/index.aspx?page=San-pham";

        public const string contronl_gioithieu = "~/Page/gioithieu.ascx";
        public const string contronl_sanphammoi = "~/Page/sanpham_moi.ascx";
        public const string contronl_showsanpham = "~/Page/sanpham.ascx";
        public const string contronl_lienket = "~/Page/Dia_diem_lienket.ascx";
        public const string contronl_register = "~/Page/register.ascx";
        public const string contronl_help = "~/Page/ho_tro.ascx";
        public const string contronl_Tim_kiem = "~/Page/result.ascx";
        public const string contronl_giohang = "~/Page/gio_hang.ascx";
        public const string contronl_Thank = "~/Page/Thank_oder.ascx";
        public const string contronl_Donhang = "~/Page/Donhang_.ascx";
        public const string contronl_Donhanglog = "~/Page/Sanpham_damua.ascx";
        //-----------------Trang chuyen de----------------------------------
        public const string contronl_Sua_cho_ba_bau = "~/Page/Sua-cho-ba-bau.ascx";
        public const string contronl_Sua_cho_tre_em = "~/Page/Sua_cho_tre_em.ascx";
        public const string contronl_Do_choi_cho_be = "~/Page/Do_choi_cho_be.ascx";
        public const string contronl_Dung_cu_va_do_an = "~/Page/Dung_cu_va_do_an.ascx";
        public const string contronl_Dinh_duong = "~/Page/Dinh_duong.ascx";
        public const string contronl_Goc_tu_van = "~/Page/Goc_tu_van.ascx";
        public const string contronl_Quan_an = "~/Page/Quan_an.ascx";
        public const string contronl_Cafe_kem_banh = "~/Page/Cafe_kem_banh.ascx";
        public const string contronl_Mua_sam_thoi_trang = "~/Page/Mua_sam_thoi_trang.ascx";
        public const string contronl_San_pham_chuc_nang = "~/Page/San_pham_chuc_nang.ascx";
        public const string contronl_San_pham_cong_nghe = "~/Page/San_pham_cong_nghe.ascx";
        public const string contronl_Phan_mem = "~/Page/Phan_mem.ascx";

        public const string contronl_Quenmatkhau = "~/Page/Quen-mat-khau.ascx";

        public const string contronl_thong_tin_tu_van = "~/Page/Goc_tu_van_detail.ascx";
        public const string contronl_thong_tin_suc_khoe = "~/Page/Dinh_duong_detail.ascx";
        public const string contronl_tuyen_dung = "~/Page/tuyen_dung.ascx";
    
        //-----------------Admin----------------------------------
        public const string contronl_Quanly_sanpham = "~/admin/quanly_sanpham.ascx";
        public const string contronl_nap_tien = "~/admin/nap_tien.ascx";
        public const string contronl_Lich_su_nap_tien = "~/admin/Lich_su_nap_tien.ascx";
        public const string contronl_Dangky = "~/admin/dangky.ascx";
        public const string contronl_Acti = "~/admin/acti.ascx";
        public const string contronl_User = "~/admin/Staff_.ascx";
        public const string contronl_nhom_san_pham = "~/admin/addCategory.ascx";
        public const string contronl_san_pham = "~/admin/addProduct.ascx";
        public const string contronl_Them_san_pham = "~/admin/addProduct.ascx";
        public const string contronl_kiem_tra_len_cap = "~/admin/kiemtra_lencap.ascx";
        public const string contronl_cau_hinh = "~/admin/cau_hinh.ascx";
        public const string contronl_address = "~/admin/address.ascx";
        public const string contronl_quanly_donhang = "~/admin/quanly_donhang.ascx";
        public const string contronl_quanly_Chitietdonhang = "~/admin/chi_tiet_donhang.ascx";
        public const string contronl_quanly_Documnet = "~/admin/Documnet.ascx";
        public const string contronl_quanly_goiy = "~/admin/xemgopy.ascx";
        public const string contronl_quanly_goiy_detail = "~/admin/Feback_detail.ascx";
        public const string contronl_Edit_New = "~/admin/Edit_New.ascx";
        public const string contronl_quanly_New = "~/admin/Edit_New.ascx";
        public const string contronl_quanly_wTintuc_slider = "~/admin/wTintuc_slider.ascx";
        public const string contronl_quanly_wTintuc_New = "~/admin/wTintuc_new.ascx";

        private const string slash = "/";
        protected string templatePath = string.Empty;

        public static string AppendQueryString(string url, string queryString)
        {
            return string.Format("{0}{1}{2}", url, (url.IndexOf('?') >= 0) ? "&" : "?", queryString);
        }

        public static string Combine(string path1, string path2)
        {
            return (path1 + "/" + path2);
        }

        public static string CompleteHttpUrl(bool isSSL, params string[] partialUrls)
        {
            int port = HttpContext.Current.Request.Url.Port;
            if ((80 != port) && (0x1bb != port))
            {
                partialUrls[0] = string.Format("{0}:{1}", partialUrls[0], port);
            }
            string str = Regex.Replace(Regex.Replace(string.Join("/", partialUrls), @"\/+", "/"), @"\/$", "");
            return ("http" + (isSSL ? "s" : "") + "://" + str);
        }

        public static string ConcatenatePartsToUrl(params string[] names)
        {
            StringBuilder builder = new StringBuilder();
            foreach (string str in names)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    if (0 == builder.Length)
                    {
                        builder.Append(str);
                    }
                    else
                    {
                        builder.Append("/").Append(str);
                    }
                }
            }
            return builder.ToString();
        }

        private static string GetApplicationPath()
        {
            if ("/" == HttpContext.Current.Request.ApplicationPath)
            {
                return "";
            }
            return HttpContext.Current.Request.ApplicationPath;
        }

        public static string GetFirstPath(string urlPath)
        {
            Match match = Regex.Match(urlPath, @"^\/?(?<firstPath>[^\/]+)\/");
            if (match.Success)
            {
                return match.Groups["firstPath"].Value;
            }
            return string.Empty;
        }

        public static string GetRelativePathToApplicatonRoot(string fullPath)
        {
            string applicationPath = GetApplicationPath();
            if (0 == applicationPath.Length)
            {
                return RemoveHeadingSlash(fullPath);
            }
            Match match = Regex.Match(fullPath, @"^\/?" + applicationPath + "(.*)$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                return RemoveHeadingSlash(match.Groups[1].Value);
            }
            return fullPath;
        }

        private static string GetStore(string urlPath)
        {
            return GetFirstPath(urlPath);
        }

        private static string MigrateRewriteUrl(string page)
        {
            if (page.Equals("product", StringComparison.OrdinalIgnoreCase) || page.Equals("category", StringComparison.OrdinalIgnoreCase))
            {
                return string.Format("Store/{0}", page);
            }
            return page;
        }

        private static string RemoveHeadingSlash(string path)
        {
            if (path.StartsWith("/"))
            {
                return path.Substring(1);
            }
            return path;
        }

        public static string RemoveHostFromUrl(string fullPathWithHost)
        {
            Match match = Regex.Match(fullPathWithHost, @"^https?:\/\/[^\/]+(.*)$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                return match.Groups[1].Value;
            }
            return fullPathWithHost;
        }

        public static string ResolveUrl(string relativePathToApplicationRoot)
        {
            return (GetApplicationPath() + "/" + relativePathToApplicationRoot);
        }

        public static string ResolveUrlInText(string text)
        {
            return text.Replace("~", GetApplicationPath());
        }

        public static string UnMapPath(string filespec)
        {
            string physicalApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath;
            if (!filespec.StartsWith(physicalApplicationPath, StringComparison.OrdinalIgnoreCase))
            {
                throw new ApplicationException(string.Format("{0} is not inside application path {1}.", filespec, physicalApplicationPath));
            }
            return ResolveUrl(RemoveHeadingSlash(filespec.Substring(physicalApplicationPath.Length).Replace('\\', '/')));
        }

        public static string UpdateUrl(string url, Dictionary<string, string> queryStringReplacement, ICollection<string> queryStringRemoval)
        {
            string str;
            string str2;
            int index = url.IndexOf('?');
            if (-1 == index)
            {
                str = url;
                str2 = string.Empty;
            }
            else
            {
                str = url.Substring(0, index);
                str2 = url.Substring(index + 1);
            }
            Dictionary<string, bool> dictionary = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
            Dictionary<string, string> dictionary2 = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            foreach (string str3 in str2.Split(new char[] { '&' }))
            {
                if (!string.IsNullOrEmpty(str3))
                {
                    string[] strArray = str3.Split(new char[] { '=' });
                    if (strArray.Length > 0)
                    {
                        string key = strArray[0];
                        if (queryStringReplacement.ContainsKey(key))
                        {
                            dictionary2[key] = queryStringReplacement[key];
                            dictionary[key] = true;
                        }
                        else
                        {
                            dictionary2[key] = (strArray.Length > 1) ? strArray[1] : string.Empty;
                        }
                    }
                }
            }
            foreach (string str5 in queryStringReplacement.Keys)
            {
                if (!dictionary.ContainsKey(str5))
                {
                    dictionary2[str5] = queryStringReplacement[str5];
                }
            }
            Dictionary<string, bool> dictionary3 = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
            if (null != queryStringRemoval)
            {
                foreach (string str5 in queryStringRemoval)
                {
                    dictionary3[str5] = true;
                }
            }
            StringBuilder builder = new StringBuilder(str);
            bool flag = true;
            foreach (string str5 in dictionary2.Keys)
            {
                if (!dictionary3.ContainsKey(str5))
                {
                    if (flag)
                    {
                        builder.Append("?");
                        flag = false;
                    }
                    else
                    {
                        builder.Append("&");
                    }
                    builder.Append(str5);
                    if (!string.IsNullOrEmpty(dictionary2[str5]))
                    {
                        builder.Append("=").Append(dictionary2[str5]);
                    }
                }
            }
            return builder.ToString();
        }
    }
}

